The present invention relates to the technical field of an application program log. In particular, the invention especially relates to a method and a system in which an original log method of an application program is optimized and newly injected to the application program.
A log method for an application program is a method in which the application program is injected to some instructions of the code of the program itself at time of development, so as to be used to record various events that occur when the program is executed and monitor execution of the program, and thereby to help to learn execution states of the system and the program and to diagnose problems that occur. For example, in order to monitor for an error in network connection that may occur at time of execution of an application program, it is possible to insert a relevant log method into the program and record information corresponding to the occurred error in network connection, such as IP address, error time, or the like, into a log file so that a program administrator can perform analysis and diagnosis thereon. Research shows that about 5 application program code is specifically provided to record a program log.
A known program log system is shown in FIG. 2, in which the code of the program itself and the code for a log method for generating a log record are included in an application program 201. Under a real-time execution environment 202, the generation of a log record may be triggered by the application program during execution, and log information 204 may be generated by performing the log method 203. Log information 204 is generally provided in a form of files, and is stored on a hard disk or other storage medium.
Hitherto, there are two major problems that exist in the known program log record generation methodology. The first major problem is that the generation of the program log record may consume a large amount of hardware resources to store the log files. During execution of the program, there may be a large amount of log information to be recorded in the hard disk or other storage means, and there is no limit on the size of the log information. Due to a limitation of the hard disk capacity, the older log information may be automatically removed, resulting in a loss of important information. The second major problem is that recording a large amount of log information may cause frequent IO (input and output) operations, and thus, the speed of execution of the application program is reduced.
In the known mechanisms, technical schemes for solving the above problems include using a log policy that is adjusted based on performance overhead, which indicates the resources occupied by the log record generation operation. Essentially, this existing technical scheme achieves an improvement in performance at the sacrifice of integrity of the log information. This technical scheme also suffers from the problem of loss of log information and can be adopted only at time of development of the application program. Moreover, the size of the log file cannot be reduced without modifying the existing program code and the log record mechanism (legacy mechanism). For another known technical scheme, the existing log record mechanism is manually altered requiring a large amount of time and an in-depth understanding of the program code, which is not feasible in practice.